function showMomSingle(statName,AddFiName,dirMom,strMom,NC)
%showMomSingle - show mom timeseries
%
%   showMomSingle(statName,AddFiName,dirMom,strMom,NC)
%
% This function shows the timeseries related to the station statName,
% whose '.mom' filename has the optional string AddFiName (e.g. AddFiname 
% can be '.EU') and whose folders are in the cell array of strings
% dirMom (if no more than a directory is considered, dirMom can be a 
% string).
%
% If AddFiName is undefined or empty, AddFiName = '' is used.
%
% If dirMom is undefined or empty, the default choice 
%   dirMom = {'raw_files','obs_files','pre_files','mom_files'} 
% is used.
%
% If strMom is a cell array of strings having the same size of dirMom
% (or a string if strMom is a string), the legend of the k-th time series
% is strMom{k}. If strMom is undefined, empty or has a size different
% from the dirMom one, the legend of the k-th time series is dirMom{k}.
%
% NC is the number of components to be shown. Admitted values: 2 (E-N),
% 3 (E-N-V). If NC is undefined, empty or is not an admitted value,
% NC = 3 is used.
%
% See also showMom.

% G. Teza, 2022

if (nargin < 5) || isempty(NC) || (numel(NC) > 1) || ~ismember(NC,[2 3])
    NC = 3;
end

if nargin == 4 && ischar(strMom)     % to have a case only
    strMom = {strMom};
end

if nargin == 3 && ischar(dirMom)    % to have a case only   
    dirMom = {dirMom};
end
if nargin < 3 || isempty(dirMom)
    dirMom = {'raw_files','obs_files','pre_files','mom_files'};
end
if (nargin < 4) || ~iscell(strMom) || ~isequal(size(strMom),size(dirMom))
    strMom = [];
end

if nargin < 2 || isempty(AddFiName)
    AddFiName = '';
elseif ~strcmpi(AddFiName(1),'.')
    AddFiName = ['.' AddFiName];
end

ndirs = numel(dirMom);

colC = {'k','g','m','b','r','c'};
nC = numel(colC);
    
figure('Name',[statName ' station'],'Units','normalized','Position',[0 0 1 1]);
for k = 1:NC
    subplot(NC,1,k);
    hold on; 
    ckn = k-1; 
    cks = num2str(ckn);
    legk = cell(0);
    npc = 1;
    for kk = 1:ndirs
        Akk = [];
        dirMomkk = dirMom{kk};
        dirMomExkk = dirMomkk;
        if ~isempty(strMom)
            strtskk = strMom{kk};
        else
            strtskk = dirMomkk;
        end
        filenakk = fullfile(dirMomExkk,[statName AddFiName '_' cks '.mom']);
        if exist(filenakk,'file') == 2
            [~,Akk] = txtReadData(filenakk);
        end
        if ~isempty(Akk)
            nckk = size(Akk,2);
            tkk = Akk(:,1);
            tkk = MJD2serial(tkk);
            Vkk = Akk(:,2);
            n = rem(npc,nC);
            plot(tkk,Vkk,['.' colC{n}]);
            if nckk == 3    % in this case, there is a model (third column)
                npc = npc+1;
                n = rem(npc,nC);
                Mkk = Akk(:,3);     % model
                plot(tkk,Mkk,colC{n});
                legkk = {strtskk,[strtskk ' model']};
            else
                legkk = {strtskk};
            end
            legk = [legk legkk]; %#ok<AGROW>
            npc = npc+1;
        end
    end
    legend(legk);
    xlabel('\it Date'); 
    datetick('x');
    if k == 1
        strC = 'East';
    elseif k == 2
        strC = 'North';
    else
        strC = 'Vertical';
    end
    ylabel(sprintf('%s (mm)',strC));
    grid on;
end